<?php

namespace App\Dao;


use App\Model\UserExt;
use App\Utils\MemcacheClient;
use Hyperf\Context\ApplicationContext;

class UserExtDao
{
    protected static $instance;

    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = Applicationcontext::getcontainer()->get(self::class);
        }
        return self::$instance;
    }

    /**
     * Note - 获取用户个人交友条件，查询扩展信息列表
     * DateTime 2024/7/17 11:07
     * User Admin
     * @param $uid
     * @return array|mixed|null
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    public function getSpaceInfoMemcache($uid)
    {
        $info = MemcacheClient::getInstance()->get("user_spaceinfo_condition_" . $uid);
        if ($info === false) {
            $info = UserExt::where('uid', $uid)->first();
            $info = modelToArray($info);
            if ($info) {
                MemcacheClient::getInstance()->set("user_spaceinfo_condition_" . $uid, $info, 300);
            }
        }
        return $info;
    }

    /**
     * Note - 是否存在扩展信息
     * DateTime 2024/7/17 11:06
     * User Admin
     * @param $uid
     * @return bool
     */
    public function userExtExist($uid)
    {
        return UserExt::where('uid', $uid)->exists();
    }

}